package com.example.fw;

import java.util.Set;


public class Contacts {

	@Override
	public String toString() {
		return "Contacts [" + contactsList + "]";
	}

	public Set<ContactObject> contactsList;

	public Contacts(Set<ContactObject> groupList) {
		this.contactsList = groupList;
	}

	public Contacts withAdded(ContactObject validContact) {
		Contacts contact = new Contacts(contactsList);
		validContact.setId("$$$");
		contact.contactsList.add(validContact);
		validContact.setId(null);
		return contact;
	}

	public Contacts withRemoved(ContactObject validContact) {
		Contacts contact = new Contacts(contactsList);
		contact.contactsList.remove(validContact);
		return contact;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((contactsList == null) ? 0 : contactsList.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Contacts other = (Contacts) obj;
		if (contactsList == null) {
			if (other.contactsList != null)
				return false;
		} else if (!contactsList.equals(other.contactsList))
			return false;
		return true;
	}
}
